package game.Config;


import game.GameHud;
import game.LevelManager;

import java.awt.Font;
import java.util.HashMap;

import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.geom.Vector2f;

/**
 * This class contains general configurations for the game.
 * @author Sebastian Isheden and Victor Beer
 *
 */
public class Config {
	
	public static Image playerImage;
	public static Image basicEnemyImage;
	public static Image healthBarImage;
	public static Image rocketTowerImage;
	public static Image quitImage;
	public static Image moneyImage;
	public static Image standardBulletImage;
	public static Image iceBulletImage;
	public static Image iceEffectImage;
	public static Image rocketBulletImage;
	public static Image mineBulletImage;
	public static Image mainMenuBakground;
	
	private static Image gameHudGoldImage;
	public static Image advancedMenuMarkerImage;
	public final static float ADVANCED_MENU_MARKER_HEIGHT = 32;
	public final static float ADVANCED_MENU_MARKER_GAP = 10;
	
	public static Image helpBuildImage;
	public static Image helpEnemyImage;
	public static Image helpMoneyImage;
	public static Image helpMoveImage;
	public static Image helpShootImage;
	public static Image helpObjectiveImage;
	
	public static SpriteSheet deathSheet;
	public static SpriteSheet fireSheet;
	public static SpriteSheet explosionSheet;
	public static final int STANDARD_DURATION = 50;
	
	//HUD INFORMATION
	public final static int HUD_HEIGHT = 40;
	public final static int FONT_SIZE = 15;
	public static Font hudFont;
	private final static Color HUD_BACKGROUND_COLOR = Color.lightGray;
	private final static Color HUD_FONT_COLOR = Color.yellow;
	private final static int HUD_LEFT_OFFSET = 30;
	private final static int HUD_SPACING = 10;
	private final static int HUD_RIGHT_OFFSET = 100;
	
	
	public final static int SCREEN_HEIGHT = 600;
	public final static int SCREEN_WIDTH = 800;
	public final static int MILLISECONDS = 1000;
	public final static float PLAYER_COLLISION_PERCENT = 0.2f; //How big the player hitbox will be compared to the player image.
	public final static int PLAYER_SPEED = 200;
	public final static Vector2f PLAYER_START_POSITION = new Vector2f(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
	
	public final static Vector2f MAIN_MENU_POSITION = new Vector2f(SCREEN_WIDTH/2, 20);
	public final static int MAIN_MENU_GAP = 30;
	public final static Color STANDARD_COLOR = Color.white;
	public final static Color SELECTED_COLOR = Color.red;
	public static final float ADVANCED_MENU_INTERVAL = 0.2f; //the time to it takes for the advanced menu marker to move between targets.
	public static final Vector2f DIFFICULTY_MENU_POSITION = new Vector2f(SCREEN_WIDTH/2-50,20);
	public static final Vector2f DIFFICULTY_POSITION = new Vector2f(SCREEN_WIDTH/4,SCREEN_HEIGHT/2+40);
	
	public static final Vector2f HELP_MENU_POSITION = new Vector2f(20,50);
	public static final int HELP_MENU_GAP = 25;
	public static final Vector2f HELP_INFO_POSITION = new Vector2f(200,50);
	public static final Vector2f HELP_INFO_OFFSET = new Vector2f(50,50);
	
	public static final Vector2f TOWER_MENU_POSITION = new Vector2f(20,SCREEN_HEIGHT/2);
	public static final Vector2f TOWER_UPGRADE_INFO_POSITION = new Vector2f(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);
	public static final float SELECTED_IMAGE_SCALE = 1.5f;
	public static final int TOWER_MENU_GAP = 80;
	public static final float TOWER_INFO_OFFSET = 20f;
	public static final float TOWER_INFO_STARTOFFSET = 40f;
	public static final float TOWER_UPGRADE_TEXT_OFFSET = 200f;
	public final static Color SIGHT_RADIUS_COLOR = Color.red;
	public final static Color TOWER_INFO_COLOR = Color.black;
	
	public static final int HEALTH_BAR_HEIGHT = 2;
	public static final int HEALTH_BAR_WIDTH = 30;
	public final static Vector2f HEALTH_BAR_OFFSET = new Vector2f(-HEALTH_BAR_WIDTH/2,- 16 - HEALTH_BAR_HEIGHT*2);
	
	public static final HashMap<Integer, GameInput> KEYMAP = new HashMap<Integer, GameInput>();

	public static final String BACKGROUND_LEVEL = "easyMap.tmx";

	
	
	public static final int IMPASSABLE_TILE_ID = 4;
	public static final int UNBUILDABLE_TILE_ID = 5;
	
	public static final int START_NODE_ID = 1;
	public static final int NODE_ID = 2;
	public static final int END_NODE_ID = 3;
	
	public static final float TILE_PIXEL_AMOUNT = 32f;

	public static final int BACKGROUND_LAYER_ID = 0;
	public static final int COLLISION_LAYER_ID = 1;
	public static final int NODE_LAYER_ID = 2;

	public static final float ENEMY_PROXIMITY_RANGE = 10f; //When the target switches node
	public static final float ENEMY_STANDARD_SPEED = 50f;
	public static final float ENEMY_STANDARD_HEALTH = 5f;
	public static final int ENEMY_COLLISION_RANGE = 12; //When the target gets hit
	public static final float MONEY_MULTIPLIER = 1f;
	
	public static final int ROCKET_MAXIMUM_TARGETS = 10;
	
	public static final boolean testing = false;
	public static final int PLAYER_START_GOLD = 400;
	public static final int EASY_AMOUNT = 50;
	public static final int MEDIUM_AMOUNT = 25;
	public static final int HARD_AMOUNT = 10;
	public static final int EGGHARD_AMOUNT = 2;
	/**
	 * Initializes the images used.
	 * @throws SlickException
	 */
	public static void initialize() throws SlickException{
		hudFont = new Font(null, Font.BOLD, FONT_SIZE);
		Weaponry.initialize();
		intializeImages();
		WaveConfig.initialize();
		LevelManager.initialize();
		TowerConfig.initialize();
		intializeKeyMap();
		
		GameHud.initialize(gameHudGoldImage, hudFont, HUD_HEIGHT, HUD_LEFT_OFFSET, HUD_RIGHT_OFFSET, HUD_SPACING, HUD_BACKGROUND_COLOR, HUD_FONT_COLOR);
	}
	

	private static void intializeImages() throws SlickException {
		
		playerImage = new Image("PlayerImage.png");
		healthBarImage = new Image("HealthBarOutline.png");
		quitImage = new Image("Quit.png");
		moneyImage = new Image("Money.png");
		
		basicEnemyImage = new Image("BasicEnemyImage.png");

		rocketTowerImage = new Image("RocketTower.png");
		standardBulletImage = new Image("BulletImage.jpg");
		iceEffectImage = new Image("IceEffect.png");
		iceBulletImage = new Image("IceBullet.jpg");
		rocketBulletImage = new Image("Rocketbullet.png");
		mineBulletImage = new Image("MineBullet.png");
		mainMenuBakground = new Image("MainMenuBakground.png");
		
		deathSheet = new SpriteSheet("BloodExplosion.png",32,32);
		fireSheet = new SpriteSheet("FireEffect.png",8,8);
		explosionSheet = new SpriteSheet("ExplosionSheet.png",64,64); //TODO, new image
		
		gameHudGoldImage = new Image("Gold.png");
		advancedMenuMarkerImage = new Image("MenuMarker.png");
		
		helpBuildImage = new Image("helpBuildImage.png");
		helpEnemyImage = new Image("helpEnemyImage.png");
		helpMoneyImage = new Image("helpMoneyImage.png");
		helpMoveImage = new Image("helpMoveImage.png");
		helpShootImage = new Image("helpShootImage.png");
		helpObjectiveImage = new Image("helpObjectiveImage.png");
	}

	private static void intializeKeyMap() {
		KEYMAP.put(Input.KEY_A, GameInput.LEFT);
		KEYMAP.put(Input.KEY_D, GameInput.RIGHT);
		KEYMAP.put(Input.KEY_W, GameInput.UP);
		KEYMAP.put(Input.KEY_S, GameInput.DOWN);
		KEYMAP.put(Input.KEY_SPACE, GameInput.ACTION);
		KEYMAP.put(Input.KEY_ESCAPE, GameInput.BACK);
		KEYMAP.put(Input.KEY_TAB, GameInput.ACTION2);
		KEYMAP.put(Input.KEY_Q, GameInput.ACTION3);
		KEYMAP.put(Input.KEY_B, GameInput.BUILD);
		KEYMAP.put(Input.MOUSE_LEFT_BUTTON, GameInput.MOUSE);
		
	}
	/**
	 * Enumeration of all the possible input types that the game will react to.
	 */
	public enum GameInput {
		UP,
		DOWN,
		LEFT,
		RIGHT,
		ACTION,
		ACTION2,
		ACTION3,
		BUILD,
		BACK,
		MOUSE,
	}
}
